<template>
	<view class="csPopupView">
		<view class="title" :style="{'height': navHeight+statusBarHeight + 'px'}">
			<text class="iconfont iconhuaban73" @tap="$emit('close')"></text>
			<text>转客服</text>
		</view>
		<view v-if="!listData.loading && listData.list<1">暂无数据</view>
		<view class="box" v-for="item in listData.list" :key="item.id" @click="itemClickEvent(item.im_account)">
			<image src="@/static/common/avator.png"></image>
			<view class="info">
				<view class="name">{{item.name}}</view>
				<view class="status" v-if="item.online">在线</view>
			</view>
		</view>
	</view>
</template>

<script>
	import customeApi from '@/service/custome.js'
	export default {
		components: {
		},
		computed: {
			navHeight() {
				return this.$store.state.system.navBarHeight
			}, // Nav栏高度
			statusBarHeight() {
				let systemInfo = uni.getSystemInfoSync()
				return systemInfo.statusBarHeight || 0
			}
		},
		data() {
			return {
				listData:{
					loading:false,
					list:[]
				}
			}
		},
		props:['chat_id'],
		mounted() {
			this.getChangeList();
		},
		methods: {
			getChangeList(){
				this.listData.loading = true;
				customeApi.changeList({
					chat_id:this.chat_id
				}).then(res=>{
					if(res.code==1){
						this.listData.list = res.data.list
					}else{
						uni.showToast({
						    title: res.msg,
						    duration: 2000
						});
					}
				}).catch(err=>{
					
				}).finally(r=>{
					this.listData.loading = false;
				})
			},
			itemClickEvent(im_account){
				uni.showModal({
				    title: '提示',
				    content: '确认转换客服？',
				    success: (con) => {
				        if (con.confirm) {
							uni.showLoading({
							    title: '加载中...'
							});
							customeApi.changeKefu({
								chat_id:this.chat_id,
								new_account:im_account
							}).then(res => {
								uni.showToast({
								    title: res.msg,
								    duration: 2000
								});
								uni.navigateTo({
									url:'/pages_customer/pages/list'
								})
							}).catch(err=>{
								
							}).finally(r=>{
								uni.hideLoading()
							})
				        }
				    }
				});
			}
		}
	}
</script>

<style lang="scss">
	.csPopupView {
		overflow: hidden;
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100%;
		background-color: #fff;

		.title {
			display: flex;
			width: 100%;
			height: 88rpx;
			background: #F6F7FB;
			align-items: center;

			.iconhuaban73 {
				font-size: 36rpx;
				color: #333333;
				padding: 0 20rpx;
			}

			.serch {
				display: flex;
				align-items: center;
				width: 422rpx;
				height: 62rpx;
				background: #FFFFFF;
				border-radius: 34rpx;

				.iconhuaban18 {
					font-size: 32rpx;
					color: #939393;
					padding: 0 20rpx 0 10rpx;
				}

			}
		}
		.box{
			display: flex;
			margin-bottom: 10rpx;
			padding: 28rpx 32rpx;
			cursor: pointer;
			&:hover{
				background-color: #f5f5f5;
			}
			&>image{
				width: 96rpx;
				height: 96rpx;
				margin-right: 24rpx;
			}
			.info{
				flex: 1;
				.name{
					font-size: 26rpx;
					color: #333;
				}
				.status{
					font-size: 22rpx;
					color: #33DA98;
				}
			}
		}
	}
</style>
